/**
 * Project: apollo-base-tools
 * 
 * File Created at 2017年8月11日
 * 
 * Copyright 2015-2016 dx.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DongXue software Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dx.com.
 */
package org.apollo.base.tools.ui.panel;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

/**
 * @ClassName: FileComparePanel
 * @Description:文件比较
 * @author wuzhenfang(wzfbj2008@163.com)
 * @date 2017年8月11日 下午3:38:11
 * @version V1.0
 */
public class FileComparePanel extends BaseJPanel {

	private static final long serialVersionUID = -8214113926448221270L;

	/** 目标目录BBB */
	private JTextField dir2;
	/** 源目录AAA */
	private JTextField dir1;
	/** 底部状态条 */
	private JLabel lb;
	/** 比较目录返回集合AAA */
	private Vector<File> vector_a = new Vector<File>();
	/** 被比较目录返回集合BBB */
	private Vector<File> vector_b = new Vector<File>();

	private JPanel contentPane;
	private JRadioButton RButton;
	private JRadioButton RButton_1;

	/** 比较目录Jlist */
	private JList list_a;

	/** 源目录路径字符创 */
	private String dir_a;
	/** 目标目录路径字符创 */
	private String dir_b;
	/**
	 * 复制进度状态栏，用来打印一些复制信息。
	 */
	private JLabel clb;

	/** 被比较目录Jlist */
	private JList list_b;
	/** 比较包括子目录 */
	private JCheckBox c_isSubDir;
	/** 比较目录 */
	private JCheckBox c_dir;

	/** 比较文件 */
	private JCheckBox c_file;
	/** 比较修改文件时间 */
	private JCheckBox c_fileTime;
	/** 比较文件K值大小 */
	private JCheckBox c_fileSize;

	/** 错误日志文本框，用来打印错误日志 */
	private JTextArea cta;
	private JProgressBar progressBar;

	public FileComparePanel() {
		setLayout(new BorderLayout());
		init();
	}

	/**
	 * Create the frame.
	 */
	public void init() {
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		add(contentPane);

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

		JLabel lblNewLabel = new JLabel("准备复制文件同步目录，请选择同步方向。");
		lblNewLabel.setForeground(SystemColor.inactiveCaptionText);
		panel.add(lblNewLabel);

		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(new BorderLayout(0, 0));

		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(null, "同步选项", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		FlowLayout flowLayout_1 = (FlowLayout) panel_3.getLayout();
		flowLayout_1.setAlignment(FlowLayout.LEFT);
		panel_1.add(panel_3, BorderLayout.NORTH);

		RButton = new JRadioButton("顺序同步");
		RButton.setToolTipText("按着原始目录同步目标目录的方向复制不相同的文件。");
		RButton.setSelected(true);
		panel_3.add(RButton);

		RButton_1 = new JRadioButton("反向同步");
		RButton_1.setToolTipText("按着从目标目录复制到原始目录中不同的文件。");
		panel_3.add(RButton_1);

		JPanel panel_2 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_2.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		contentPane.add(panel_2, BorderLayout.SOUTH);

		JButton btnNewButton = new JButton("ok");
		btnNewButton.setToolTipText("开始复制同步文件。");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (RButton.isSelected()) {
					// System.out.println("准备创建线程开始复制"+v_a.size());
					// CopyThread copy = new CopyThread("copy", v_a, dir_a, dir_b, clb, cta, progressBar);
					// copy.start();

				}
				if (RButton_1.isSelected()) {
					// System.out.println("准备创建线程开始复制"+v_b.size());
					// CopyThread copy1 = new CopyThread("copy", v_b, dir_b, dir_a, clb, cta, progressBar);
					// copy1.start();
				}
			}
		});
		panel_2.add(btnNewButton);

		JButton btnNewButton_1 = new JButton("cancel");
		btnNewButton_1.setToolTipText("取消");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// dispose();
			}
		});
		panel_2.add(btnNewButton_1);

		ButtonGroup buttonGroup = new ButtonGroup();
		buttonGroup.add(RButton);
		buttonGroup.add(RButton_1);

		JPanel panel_4 = new JPanel();
		panel_1.add(panel_4, BorderLayout.CENTER);
		panel_4.setLayout(new BorderLayout(0, 0));

		progressBar = new JProgressBar();
		progressBar.setForeground(SystemColor.activeCaption);
		progressBar.setToolTipText("复制进度");
		progressBar.setStringPainted(true);
		progressBar.setEnabled(false);

		panel_4.add(progressBar, BorderLayout.NORTH);

		JScrollPane scrollPane = new JScrollPane();
		panel_4.add(scrollPane, BorderLayout.CENTER);

		cta = new JTextArea();
		cta.setText("操作日志，如果发生同步错误这里做一些错误记录。\r\n");
		scrollPane.setViewportView(cta);

		clb = new JLabel("点击ok开始复制文件.");
		panel_4.add(clb, BorderLayout.SOUTH);
	}

	/**
	 * @return dir_a
	 */
	public String getDir_a() {
		return dir_a;
	}

	/**
	 * @param dir_a 要设置的 dir_a
	 */
	public void setDir_a(String dir_a) {
		this.dir_a = dir_a;
	}

	/**
	 * @return dir_b
	 */
	public String getDir_b() {
		return dir_b;
	}

	/**
	 * @param dir_b 要设置的 dir_b
	 */
	public void setDir_b(String dir_b) {
		this.dir_b = dir_b;
	}

	/**
	 * @return 是否选择了顺序同步
	 */
	public boolean getRButton() {
		return RButton.isSelected();
	}

	/**
	 * @return 是否选择了反向同步
	 */
	public boolean getRButton_1() {
		return RButton_1.isSelected();
	}

	/**
	 * 开始复制同步程序。
	 * @throws IOException
	 */

}
